package com.gameplatform.common.response;

import com.gameplatform.common.enums.ResultCodeEnum;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class BaseResponse<T> {
    private int code;
    private String message;
    private T data;

    public BaseResponse(ResultCodeEnum resultCode) {
        this.code = resultCode.getCode();
        this.message = resultCode.getMessage();
    }

    public BaseResponse(ResultCodeEnum resultCode, String message) {
        this.code = resultCode.getCode();
        this.message = message;
    }

    public BaseResponse(ResultCodeEnum resultCode, T data) {
        this.code = resultCode.getCode();
        this.message = resultCode.getMessage();
        this.data = data;
    }

    public BaseResponse(ResultCodeEnum resultCode, String message, T data) {
        this.code = resultCode.getCode();
        this.message = message;
        this.data = data;
    }

    /**
     * 成功返回结果
     */
    public static <T> BaseResponse<T> success() {
        return new BaseResponse<>(ResultCodeEnum.SUCCESS);
    }

    /**
     * 成功返回结果
     * @param data 获取的数据
     */
    public static <T> BaseResponse<T> success(T data) {
        return new BaseResponse<>(ResultCodeEnum.SUCCESS, data);
    }

    /**
     * 成功返回结果
     * @param data 获取的数据
     * @param message 提示信息
     */
    public static <T> BaseResponse<T> success(T data, String message) {
        return new BaseResponse<>(ResultCodeEnum.SUCCESS, message, data);
    }

    /**
     * 失败返回结果
     * @param resultCode 错误码
     */
    public static <T> BaseResponse<T> error(ResultCodeEnum resultCode) {
        return new BaseResponse<>(resultCode);
    }

    /**
     * 失败返回结果
     * @param resultCode 错误码
     * @param message 错误信息
     */
    public static <T> BaseResponse<T> error(ResultCodeEnum resultCode, String message) {
        return new BaseResponse<>(resultCode, message);
    }

    /**
     * 参数验证失败返回结果
     */
    public static <T> BaseResponse<T> validateFailed(String message) {
        return new BaseResponse<>(ResultCodeEnum.PARAM_ERROR, message);
    }

    /**
     * 未登录返回结果
     */
    public static <T> BaseResponse<T> unauthorized(String message) {
        return new BaseResponse<>(ResultCodeEnum.UNAUTHORIZED, message);
    }

    /**
     * 未授权返回结果
     */
    public static <T> BaseResponse<T> forbidden(String message) {
        return new BaseResponse<>(ResultCodeEnum.FORBIDDEN, message);
    }
} 